<?php
/**
 * 管理员表内置数据
 */
namespace ApiBundle\DataFixtures\ORM;


use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadTableData implements FixtureInterface, ContainerAwareInterface
{

    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * {@inheritdoc}
     */
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }
    
    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        // TODO 区域内置
        $serviceFiles = $this->container->get('helper.files');
        $conn = $this->container->get('database_connection');

        $data_district = $serviceFiles->readToJson('app/data/district.json');
        foreach ($data_district as $value){
            $value['created_at'] = date('Y-m-d H:i:s');
            $conn->insert('district', $value);
        }

        // TODO 添加管理员角色
        $admin_role = $serviceFiles->readToJson('app/data/admin_role.json');
        foreach ($admin_role as $value){
            $conn->insert('admin_role', $value);
        }

        // TODO 添加平台管理员帐号
        $data_plat_admin = $serviceFiles->readToJson('app/data/admin.json');
        foreach ($data_plat_admin as $value){
            $value['created_at'] = date('Y-m-d H:i:s');
            $salt = $this->container->get('helper.strings')->generateSalt(6, true);
            $value['salt'] = $salt;
            $value['password'] = $this->container->get('helper.strings')->encryptPassword($value['password'], $salt);
            $conn->insert('admin', $value);
        }

        // TODO 添加企业类别
        $data_category = $serviceFiles->readToJson('app/data/category.json');
        foreach ($data_category as $value){
            $conn->insert('company_category', $value);
        }

        // TODO 添加企业属性
        $data_category = $serviceFiles->readToJson('app/data/attribute.json');
        foreach ($data_category as $value){
            $conn->insert('company_attribute', $value);
        }




    }

}